#include <bits/stdc++.h>
using namespace std;
int n,m,k,t,a[100101],c[100101],x[4],p[101];
bool d[101][101];
char ac;
int fk(){
    p[0]=1;
    for(int i=1;;i++){
        p[i]=p[i-1]*2;
        if(p[i]>=n)
            return i;
    }
}
void solve(){
    cin>>x[0]>>x[1]>>x[2]>>x[3];

}
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
        cin>>c[i];
    k=fk();
    for(int i=1;i<=k;i++)
        for(int j=1;j<=p[k-i];j++){
            cin>>ac;
            d[i][j]=ac-'0';
        }
    cin>>t;
    while(t--)
        solve();
    return 0;
}
